package com.xmall.pay.service.impl;

import com.xmall.msg.queue.OrderModule;
import com.xmall.msg.base.MsgSourceType;
import com.xmall.msg.entity.order.OrderPaySuccessMsg;
import com.xmall.define.request.pay.OrderPaySuccessRequest;
import com.xmall.pay.service.IMsgService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MsgServiceImpl implements IMsgService {

    @Resource
    private RabbitTemplate rabbitTemplate;


    /**
     * 发送支付成功消息
     */
    @Override
    public void sendPaySuccessMsg(OrderPaySuccessRequest request) {
        OrderPaySuccessMsg msg = new OrderPaySuccessMsg().build(MsgSourceType.ORDER, OrderModule.OrderPaySuccess.ORDER_PAY_SUCCESS_FANOUT_EXCHANGE, OrderModule.OrderPaySuccess.ORDER_PAY_SUCCESS_QUEUE)
                .info(request.getOrderId(), request.getOrderSn(), request.getTradeNo(), request.getPayTime(), request.getPayType(), request.getPayPlatform());
        rabbitTemplate.convertAndSend(OrderModule.OrderPaySuccess.ORDER_PAY_SUCCESS_FANOUT_EXCHANGE, OrderModule.OrderPaySuccess.ORDER_PAY_SUCCESS_QUEUE, msg, new CorrelationData(msg.getCorrelationKey()));
    }
}
